﻿#region Copyright Bearingpoint GDC May 2005
// =====================================================================================
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, electronic, mechanical or otherwise, is prohibited
// without the prior written consent of the copyright owner.
//
// Author:John Shao May 26 2005
// =====================================================================================
#endregion

using System;
using System.Configuration;
using System.Collections.Specialized;

using BEGDC.Utility.ExceptionManagement;

namespace BEGDC.Utility.Configuration
{
	public delegate void ConfigEventHandler();

	/// <summary>
	/// Summary description for Configuration.
	/// </summary>
	public abstract class Configuration
	{
		private NameValueCollection configs;

		public Configuration()
		{
			this.Load();
		}

		public abstract string ModuleName
		{
			get;
		}

		protected void Load()
		{
			try
			{
				configs = (NameValueCollection)ConfigurationSettings.GetConfig(ModuleName);
			}
			catch(Exception e)
			{
				throw new GDCException("1.0001", "Load App configuration information failed in "+this.ModuleName+".",e);
			}
		}

		public virtual string this[string name]
		{
			get
			{
				return this.GetValue(name);
			}
		}

		public virtual string GetValue(string name)
		{
			try
			{
				return configs[name];
			}
			catch(Exception e)
			{
				throw e;
			}
		}
	}
}